import { TreeNodeData } from '@arco-design/web-vue';
import axios from 'axios';

export const OrgType = {
  COMPANY: '1',
  DEPARTMENT: '2',
  GROUP: '3',
  OTHER: '4',
};

export const ORG_TYPES = [
  { label: '公司', value: OrgType.COMPANY },
  { label: '部门', value: OrgType.DEPARTMENT },
  { label: '小组', value: OrgType.GROUP },
  { label: '其他', value: OrgType.OTHER },
];

/**
 *
 * @returns 树形结构的组织
 */
export function getOrgTree(): Promise<TreeNodeData[]> {
  return axios.get('/upms/org/tree');
}

/**
 * 查询单个的信息
 */
export function getOrgById(id?: string) {
  return axios.get(`/upms/org/${id}`);
}

/**
 * 添加机构
 */
export function addOrg(data: any) {
  return axios.post('/upms/org', data);
}

/**
 * 修改机构
 */
export function updateOrg(data: any) {
  return axios.put('/upms/org', data);
}

/**
 * 删除机构
 */
export function deleteOrg(id: string) {
  return axios.delete(`/upms/org/${id}`);
}
